package com.example.travelservlet.managementLogin.dao;

import com.example.travelservlet.entity.Manager;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

/**
 * @author kiki
 * @dtae 2023/5/31 15:48
 */
public interface LoginRepository extends JpaRepository<Manager, String> {
    Manager findByUsernameAndPassword(String name, String pwd);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update manager set state=1 where id=?1", nativeQuery = true)
    Integer setManagerStateSignin(String id);

    Manager findManagerById(String userid);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update manager set state=0 where id=?1", nativeQuery = true)
    Integer setManagerStateSignout(String userid);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update manager set username=?2, password=?3 where id=?1", nativeQuery = true)
    Integer editManagerById(String id, String username, String password);
}
